package com.xyzim.firstcode.ui;

import android.app.Activity;
import android.os.Bundle;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;

import com.xyzim.firstcode.R;

import java.util.ArrayList;
import java.util.List;

public class FruitActivity extends Activity {

    private List<Fruit> fruitList= new ArrayList<>();
    private RecyclerView recyclerView;
    private FruitAdapter mAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_fruit);


        recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
        mAdapter = new FruitAdapter(fruitList);
        //LinearLayoutManager mLayoutManager = new LinearLayoutManager(getApplicationContext());
        StaggeredGridLayoutManager mLayoutManager = new StaggeredGridLayoutManager(3,StaggeredGridLayoutManager.VERTICAL);
        //mLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
        recyclerView.setLayoutManager(mLayoutManager);
        recyclerView.setItemAnimator(new DefaultItemAnimator());
        recyclerView.setAdapter(mAdapter);

        initFruitList();
    }

    public void initFruitList(){
        for(int i=0;i<20;i++) {
            Fruit fruit = new Fruit("Apple", R.drawable.apple);
            fruitList.add(fruit);
            fruit = new Fruit("Banana", R.drawable.banana);
            fruitList.add(fruit);
        }
        mAdapter.notifyDataSetChanged();
    }
}
